
def fun():
    "处理ZeroDivisionError异常"
    print("Give me two numbers, and I'll divide them.")
    print("Enter 'q' to quit ")

    while True:
        first_number = input("\n First Number:")
        if first_number == 'q':
            break
        second_number =input("\n Second Number:")
        if second_number == 'q':
            break
        try:
            answer = int(first_number)/int(second_number)
        except ZeroDivisionError:
            print("You can't divide by 0!")   #出现异常时执行改语句
        else:
            print(answer)  #程序正常执行
        finally:
            print("last step")  #不管有无异常都会执行

def fun2():
    "处理FileNotFoundError异常"
    "如果读取的文件不存在，会引发该异常"

    filename = "alice.txt"
    try:
        with open(filename) as f_obj:
            contents = f_obj.read()
    except FileNotFoundError:
        msg = "Sorry,the file "+filename+" doesn't exist."
        print(msg)
    else:
        print(contents)

if __name__ == '__main__':
    fun2()